from db import db
from fvutil import fvcon
from util import config
from presence import ps

# NOTE: Same API 
class PresenceWrapper:
        
    def __init__(self, presence):
        self.__presence = presence
        #OFFLINE = config.get_int('presence.status', 'offline')
        #ONLINE = config.get_int('presence.status', 'online')        
        
        self.__fv_to_presence_status= {
            fvcon.OFFLINE: config.get_int('presence.status', 'offline'),
            fvcon.ONLINE : config.get_int('presence.status', 'online'),
        }
    
    def get_all(self):
        print '!@#!@#!@# GETTING PRESENCE!'
        users = self.__presence.get_all_known_users()
        return map(self.to_flash, users)
    
    def get(self, uid):
        user = self.__presence.get_known_user(uid)
        return self.to_flash(user)
        
    def __to_fv_status(self, header_dict):
        if header_dict['status'] == fvcon.ONLINE:
            del header_dict['status']
            header_dict['status'] = header_dict['meta'][fvcon.STATUS]

    def to_flash(self, header_dict):
        self.__to_fv_status(header_dict)
        return {'id':header_dict['uid'], 
                'label':header_dict['name'], 
                'address':'unknown..', # TODO: Do we need address?
                # TODO: Get this right
                'subcommand':fvcon.ADD,
                'type':fvcon.FV,
                'status':header_dict['status'],
                }
